Copy and paste is carried out to copy program code from a source location to paste it into a destination location in order to avoid re-typing repeated sections of program code. Copy and paste between program texts is carried out in a computer program development environment such as an integrated development environment (IDE). Currently, IDEs copy and paste program code from one program to another as flat program text, and paste is carried out as an atomic operation.
The clipboard is loaded with the copied program code from the source location and the paste destination site is located in some other program text (or in a different location within the same text). The source and destination locations will typically be in well-formed, syntax-highlighted and coloured pieces of program text for which valid abstract syntax trees (AST) have been created by the IDE. When the clipboard contents is pasted, there are frequently problems to address. For example, the newly inserted code may use unheard of variable names, or may not be a fully- or well-formed compound Java statement, or may corrupt the paste location in some other way. The result is an invalid program text that contains syntax errors.
For example, just after pasting in an additional “if statement,” a result might appear as follows:
  /*  * If not virtualised, the path in the composite instance will  * include the part name  */  parmPath = part.getName( ) + parmPath;} else {  /*  * Virtualisation, CI will refer to the new name with an empty  * path...  */  parmPath = “”;}                              if (name.equals(vparm.getName( )) && path.equals((vparmPath))) {  VirtualisedParameter virt = vparm.getVirtualization( );  If (virt == null) {     //log data state error;  }  return virt;}
The bottom “if statement” has just been pasted in. The resulting syntax errors can be seen and are shown as underlined. Such errors can occur in both the new and the old program text.
After this paste operation, the program is in exactly the same state as if the text had been typed in. Any text that has just been pasted in has no relation to the source text from which it was taken any more than it does to text that is already in the destination program. The user usually now edits the text to change variables to match the new context, etc.
The user would change all the ‘old’ names to the ‘new’ one in the pasted section manually. In the state of the art, “refactor rename” is not usable due to the syntax problems. Also, “change all” is not usable if the source location is in the same program text as the destination location (for example in a different method) and the user does not wish to change the program text.